/*
 * Copyright (C) 2008 Peter Kling
 * 
 * This file is part of 'A Kind of Billiard', a graphical billiard simulation.
 * 
 * 'A Kind of Billiard' is free software: you can redistribute it and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * 'A Kind of Billiard' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with 'A Kind of Billiard'. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package de.akob.mathematics;

/**
 * A plane in the (three dimensional) euclidean space. Internally the plane is stored in "Hesse-Normalenform".
 */
public class MathPlane3D implements Cloneable {
	private MathVector normal;
	private double     distance;
	
	/**
	 * Creates a plane with the given normal (pointing from the origin to the plane) and distance from the origin. The
	 * given normal will be normalized if it is not already.
	 * 
	 * @throws IllegalArgumentException If d is negative or the normal has length 0.
	 */
	public MathPlane3D(MathVector normal, double distance) {
		if (normal.dim != 3)
			throw new IllegalArgumentException("given normal vector not three dimensional");
		if (normal.norm() == 0)
			throw new IllegalArgumentException("given normal vector must not be the zero vector");
		if (distance < 0)
			throw new IllegalArgumentException("given distance must be non-negative");
		this.distance = distance;
		this.normal = normal;
		this.normal.normalize();
	}
	
	@Override
	protected MathPlane3D clone() {
		return new MathPlane3D(normal.clone(), distance);
	}
	
	/**
	 * Returns the distance between the origin and this plane.
	 * 
	 * @return distance to the origin
	 */
	public double getDistance() {
		return distance;
	}
	
	/**
	 * Returns a vector representing the normalized normal of this plane (pointing from the origin to the plane).
	 * 
	 * @return (normalized) normal
	 */
	public MathVector getNormal() {
		return normal;
	}
}
